<div id="result">
<form method="post" id="import_global_brand" action="<?php echo Configure::read('base_url')."add_category/editcategory";?>">
<?php echo $this->Form->input('Category.id', array( 'type' => 'hidden', 'value'=>$catid));?>
<?php echo $this->Form->input('Category.type', array( 'type' => 'hidden', 'value'=>$type));?>

<table width="100%" border="0" cellspacing="0" cellpadding="0" id="mytable">
  <tr><td colspan="2"><h5>Import Global <?php echo ucfirst($type); ?></h5></td></tr>
  <tr>
    <td width="30"><input type="checkbox" id="select_<?php echo $type; ?>_all"></td>
    <td width="97%">Select all</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
    
    	<table width="100%" border="0" cellspacing="0" cellpadding="0" class="maintable">
    	<?php $i=0;foreach ($brands as $brand):?>
    	<tr>
    	<?php 
    		$class = null;
    		$checked='';
			if ($i++ % 2 == 0)
			{
				$class = ' class="alt"';
			}
		?>
    		<td width="30" <?php echo $class;?>>
			<?php //pr($categoryBrands);
			foreach ($categoryBrands as $categoryBrand)
				{
					if ($categoryBrand['Categorybrand']['brand_id'] == $brand['Brand']['id'])
					{
						$checked = 'checked="TRUE"';
						echo'<input type="hidden" name="data[updateid]['.$brand['Brand']['id'].']" value="'.$categoryBrand['Categorybrand']['id'].'" />';
					}
				}
			?>
    			<input type="checkbox"  onclick="return chkforproduct(this);" <?php echo $checked;?> name="data[global_<?php echo $type; ?>][]" id="global_<?php echo $type; ?>" value="<?php echo $brand['Brand']['id'];?>" />
    		</td>
    		<td <?php echo $class; ?>> <?php echo $brand['Brand']['brand_description'];?></td>
    	</tr>
    	<?php endforeach;?>
	    	<tr>
		    	<td colspan="2">
		    		<table width="100%" border="0" cellspacing="0" cellpadding="0">
		      			<tr>
		        			<td width="75"><input type="submit" name="button" id="button" value="Import" /></td>
		        			<td><input type="button" name="button2" id="button2" value="Skip This!" /></td>
		      			</tr>
		    		</table>
		    	</td>
		    </tr>
    	</table>
    </td>
  </tr>
</table>

</form>
</div>
<?php  echo $html->script(array("jquery.min.js","jquery.form.js","jquery.validate.js","jquery.pagination.js","jquery.tablesorter.min.js","jquery.tablednd.js")); ?>	 
 <script type="text/javascript">  
 jQuery(document).ready(function(){
		
		var v = jQuery("#import_global_brand").validate({
			submitHandler: function(form) {
				jQuery(form).ajaxSubmit({
					target: "#result"
				});
			}
		});		
		
//Check all
		jQuery("#select_brand_all").click(function()				
			{
				var checked_status = this.checked;
				if(checked_status==false){
					if(!confirm("Are you sure you want to remove all brands form the category?")){
						return false;
					}					
				}
				
				jQuery("input[id=global_brand]").each(function()
				{
					this.checked = checked_status;
				});
			});
			
			jQuery("#select_style_all").click(function()				
			{
				var checked_status = this.checked;
				if(checked_status==false){
					if(!confirm("Are you sure you want to remove all styles form the category?")){
						return false;
					}					
				}
				jQuery("input[id=global_style]").each(function()
				{
					this.checked = checked_status;
				});
			});
			jQuery("#select_condition_all").click(function()				
			{
				var checked_status = this.checked;
				if(checked_status==false){
					if(!confirm("Are you sure you want to remove all conditions form the category?")){
						return false;
					}					
				}
				jQuery("input[id=global_condition]").each(function()
				{
					this.checked = checked_status;
				});
			});
	});
	
	function chkforproduct(param){
			if(param.checked==false)
			{
				catID=jQuery("#CategoryId").val();
				brandID=jQuery(param).val();
				var brandType="";
				if(jQuery(param).attr('id')=='global_style')
				brandType='style';
				else if(jQuery(param).attr('id')=='global_condition')
				brandType='condition';
				else
				brandType='brand';
				data="catid="+catID+"&brandid="+brandID;
				jQuery.ajax({
					type: 'POST',
					url: baseurl+"add_category/chkforproduct/"+brandType,
					data: data,
					dataType: 'json',
					success: function(data){						
						if(data.message=="Yes"){
							if(confirm("There are "+data.total+" Products Under this brands. Are you sure you want to remove form the category?")){
								
								
							}
							else
							{
								jQuery(param).attr('checked','checked');								
							}
						}else{
						
						
						}
					}			
				});
			}
		}
	jQuery('#button2').click(function(){
		disablePopup();
		return false;
		});


var sel=jQuery(".maintable tr:last").closest("td").parent();
var i=1;
var trs=jQuery(".maintable tr");
var length=trs.length-1;

function moreItem(){
    trs.show();
    trs.each(function(index){
        if(index > i*14 && index < length-1){
            jQuery(this).hide();
        }

    });
    i++;
    menuHide(parseInt(jQuery(".maintable tr:hidden").length));
}
function lessItem(){
    i=i-2;
    moreItem();
    menuHide(parseInt(jQuery(".maintable tr:hidden").length));
}

function menuHide(hiddenFields){
    diff=parseInt(length)-hiddenFields;
    if(diff<=15){
        jQuery(".less").hide();
        jQuery(".more").show();
        jQuery(".pipe").hide();
    }
    
    if(hiddenFields==0){
        jQuery(".less").show();
        jQuery(".more").hide();
        jQuery(".pipe").hide();
    }

    if(diff > 15 && hiddenFields > 0){
        jQuery(".less").show();
        jQuery(".more").show();
        jQuery(".pipe").show();
    }
}
var elem=jQuery('<tr><td></td><td style="text-align: right;"><a onclick="lessItem()" class="less"> << Less</a><span class="pipe"> || </span><a onclick="moreItem()" class="more">More >></a></td></tr>').insertBefore(sel);

jQuery("document").ready(function(){
    
        moreItem();

});
 </script>
<style type="text/css">
    .more, .less{
        cursor: pointer;
}
</style>
